﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace LibrarySystem
{
    public partial class Main : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
                if (Session["Username"] != null)
                {
                    if (Session["Admin"].ToString() == "0")
                    {
                        loginDiv.Visible = false;
                        adminDiv.Visible = false;
                        borrowerDiv.Visible = true;
                    }
                    else if (Session["Admin"].ToString() == "1")
                    {
                        loginDiv.Visible = false;
                        adminDiv.Visible = true;
                        borrowerDiv.Visible = false;
                    }
                }
        }

        protected void searchBtn_Click(object sender, ImageClickEventArgs e)
        {
            Response.Redirect("searchPage.aspx?val=" + searchDropDown.SelectedValue + "&term=" + Server.UrlEncode(searchBox.Text));
        }
              

        protected void logInModal_Click(object sender, EventArgs e)
        {
            BusinessLayer.User loggedIn = BusinessLayer.User.verifyUser(userName.Text, passWord.Text);
            if (loggedIn != null)
            {
                Session["Username"] = loggedIn.UserName;
                Session["PID"] = loggedIn.PersonId;
                Session["Admin"] = loggedIn.Admin.ToString();
            }
            if (Session["Admin"].ToString() == "1")
                Response.Redirect("adminSearch.aspx?val=bkTitle&term=");
            Response.Redirect(Request.RawUrl);
        }

        protected void logoutBtn_Click(object sender, EventArgs e)
        {
            Session.RemoveAll();
            Response.Redirect("homePage.aspx");
        }

        
    }
}